<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@include file="../../util/taglib.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>添加职位</title>
</head>
<body>
<div id="copyPermissionForm" class="easyui-layout"  data-options="fit:'true'">
     <div data-options="region:'west',split:true,title:'表单操作'" title="West" style="width:50%;padding:3px">
			<div class="form-Container">
		        <form action="${pageContext.request.contextPath}/permission/copyPermission.do"  id="dataForm" class="grayForm" method="post">
                <input type="hidden" id="uuidArray" name="uuidArray" value=""  class="easyui-validatebox" data-options="required:true"/>
                <table>
                    <tr>
                        <td ><label for="toPermissiton">拷贝到:</label></td>
                        <td style="line-height:20px;">
                          <input type="text" class="easyui-combotree" id="toPermissitonId" name="toPermissitonId"
	                           data-options="
	                                prompt:'请选择',
	                                width:244,
	                                height:25,
	                                panelHeight:300,
	                                url:'<%=basePath %>permission/getPermissionList4Tree.do',    
					        	    valueField:'id',
					        	    textField:'psmName',
					        	    required:true
					        	    "/>
                        </td>
                    </tr>
                    <tr>
                        <td ><label for="companyUUID">已选权限:</label></td>
                        <td style="line-height:20px;" class="havePms">
                            
                        </td>
                    </tr>
                    <tr>
                        <td colspan="4" style="text-align: center;">
                            <input type="button" value="提交数据" name="submitData"  />
                            <input type="button" value="关闭" name="close" />
                        </td>
                    </tr>
                </table>
                <div id="confirmMsg"></div>
            </form>
            </div>
		</div>
		<div class="permissionTree"  data-options="region:'center',title:'权限选择区'" title="Center">
		       <img alt="" src="<%=basePath %>manage/images/loading.gif" />
		</div>
	  </div>
        <script type="text/javascript">
        var baseId = "#copyPermissionForm ";
        $(document).ready(function () {
        	
        	$("#copyPermissionForm input[name='close']").click(function () {
       		    $("#editDataFormArea").window("close");
       	    })
        	
        	//加载树
        	loadPmsTree("");
        	
        	var rules = {}
        	var messages = {}
        		messages = {
        			uuidArray:"请在右边选择要开拷贝的值",
        			toPermissitonId:"请选择要拷贝的目标权限"
            };
        	var validateForm = $("#copyPermissionForm #dataForm").validate({
                debug:true,
                rules:rules,
                messages:messages
            });
        	
            //提交数据到服务器
            $(baseId+"input[name='submitData']").click(function () {
            	//提交表单进行验证
            	$(baseId+"#dataForm").form('submit',{
        			//当提交时
        			onSubmit:function(param){
        				if(!validateForm.form()){
        					return false;
        				}
        			},
        			success:function(data){
        				// change the JSON string to javascript object 
        				var data = eval('(' + data + ')');
        				if(data.code=="00"){
          				  $.messager.confirm('操作确认',data.msg+',请确认是否继续操作？',function(flag){
          					  if(flag){
          						  $("#editDataFormArea").window("close");
          						  tableObject.datagrid('reload');
          					  }
          				  });
          			    }else{
          				   $.messager.alert('操作提示',data.msg,'error');
          			    }
        			}
        		});
            });
        });
        
        //通过表单加载数据
        function loadFormData(id){
        	$.post(getBasePath()+"position/getJsonDetail.do",{id:id},function(jsonData){
        		$(baseId+" #dataForm").form("load",jsonData.data);
  		    },"json");
        }
        
        
      //加载权限树
  	  function loadPmsTree(uuid){
      	  var pmsTree = $('#copyPermissionForm .permissionTree');
      	  var url = getBasePath()+"permission/getPermissionTree.do"
      	  pmsTree.tree({
        	        url:url,
        	        method: 'post',
	          		animate: true,
	          		checkbox:true,
	          		lines:true,
	          		queryParams:{
	          			groupUUID:uuid
	          		},
	          		//单击某个节点触发的事件
	          		onCheck:function(node,checked){
	                	var nodes = pmsTree.tree('getChecked', ['checked']);
	                	var pmsStr = "";
	                	var uuidArray = "";
	          			$.each(nodes,function(i,node){
	          				pmsStr+="["+node.attributes.psmCode+"]:"+node.text+"<br/>";
	          				uuidArray+=node.id+"`";
	          			})
	          			$("#copyPermissionForm .havePms").html(pmsStr);
	          			$("#copyPermissionForm #uuidArray").val(uuidArray);
	          		},
	          		onLoadSuccess:function(node,data){
	          		}
	          		
	          });  
        }
    </script>
  </div>
</body>
</html>